package feedback.core.models.entities;

import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by lufy on 6/17/2015.
 */
@Entity
@PrimaryKeyJoinColumn(name="teacherId")
public class Teacher extends Person implements Serializable {
  
    private String teacherPro;
    @ManyToOne(fetch = FetchType.LAZY, cascade = { CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH })
    private Faculty faculty;
    @OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH })
    private List<ClassRoom> classRooms;
    @ManyToMany(fetch = FetchType.LAZY, cascade = { CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
    @JoinTable(name = "Teachers_subjects",joinColumns=@JoinColumn(name="teacherId"),inverseJoinColumns=@JoinColumn(name="subjectId") )
    private List<Subject> subjects;
    @OneToMany(fetch = FetchType.LAZY, cascade =CascadeType.ALL, mappedBy="subjectDean")
    private List<Subject> subjectDeans;
    @OneToMany(fetch = FetchType.LAZY, cascade =CascadeType.ALL, mappedBy="facultyBean")
    private List<Faculty> facultyDeans;

    @Override
    public String is() {
        return "t";
    }

    public Teacher() {

    }

 

    public String getTeacherPro() {
        return teacherPro;
    }

    public void setTeacherPro(String teacherPro) {
        this.teacherPro = teacherPro;
    }

    public Faculty getFaculty() {
        return faculty;
    }

    public void setFaculty(Faculty faculty) {
        this.faculty = faculty;
    }

    public List<ClassRoom> getClassRooms() {
        return classRooms;
    }

    public void setClassRooms(List<ClassRoom> classRooms) {
        this.classRooms = classRooms;
    }

    public List<Subject> getSubjects() {
        return subjects;
    }

    public void setSubjects(List<Subject> subjects) {
        this.subjects = subjects;
    }
    public void addSubjects(List<Subject> subjects){
        for(Subject s: subjects){
            addSubject(s);
        }
    }
    public void addSubject(Subject newSubject) {
        if (newSubject == null)
            return;
        if (this.subjects == null)
            this.subjects = new ArrayList<Subject>();
        if (!this.subjects.contains(newSubject))
            this.subjects.add(newSubject);
        newSubject.addTeacher(this);
    }

    public void removeSubject(Subject oldSubject) {
        if (oldSubject == null)
            return;
        if (this.subjects != null)
            if (this.subjects.contains(oldSubject))
                this.subjects.remove(oldSubject);
    }

    public void removeAllSubject() {
        if (subjects != null)
            subjects.clear();
    }
    public void addSubjectDean(Subject newSubject) {
        if (newSubject == null)
            return;
        if (this.subjectDeans == null)
            this.subjectDeans = new ArrayList<Subject>();
        if (!this.subjectDeans.contains(newSubject))
            this.subjectDeans.add(newSubject);
        newSubject.setSubjectDean(this);
    }

    public void removeSubjectDean(Subject oldSubject) {
        if (oldSubject == null)
            return;
        if (this.subjectDeans != null)
            if (this.subjectDeans.contains(oldSubject))
                this.subjectDeans.remove(oldSubject);
    }

    public void removeAllSubjectDean() {
        if (subjectDeans != null)
            subjectDeans.clear();
    }

	@Override
	public boolean isTeacher() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public boolean isStudent() {
		// TODO Auto-generated method stub
		return false;
	}
}
